package com.mobilesales.c2dm;

import service.ServiceClient;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.mobilesales.android.model.clients.Client;
import com.mobilesales.android.services.AuthServiceClient;
import com.mobilesales.android.services.ClientServiceClient;
import com.mobilesales.android.services.Configuration;
import com.mobilesales.c2dm.C2DMBaseReceiver;

public class C2DMReceiver extends C2DMBaseReceiver {
  public C2DMReceiver() {
    super("mobilesales88@gmail.com");
  }

  @Override
  public void onRegistered(Context context, String registrationId) {
    Log.w("C2DMReceiver-onRegistered", registrationId);
    /*synchronized(C2DMMessaging.isRegistered){
    	C2DMMessaging.isRegistered = true;
    }
	String id = registrationId;
    Configuration conf = new Configuration("http://10.0.2.2:19048/RestServices/Service.svc", "6e47537b-e105-4ee8-b847-ee45a63da473");
    //ServiceClient client = new ServiceClient(conf);
    ServiceClient client = new ServiceClient(conf);
    try{
    Integer in = client.notify(registrationId);
    //Log.i("clientid", String.valueOf(cl.Id));
     * 
     */
    try{
	    Configuration conf = new Configuration("http://10.0.2.2:19048/RestServices/Service.svc");
	    AuthServiceClient authServiceClient = new AuthServiceClient(conf);
	    DeviceRegistrer.registerWithServer(context, "uxon", "qwerty", registrationId, authServiceClient);
    } catch (Exception e){
    	Log.i("exc_onreg", e.getMessage());
    }
  }
  
  @Override
  public void onUnregistered(Context context) {
    Log.w("C2DMReceiver-onUnregistered", "got here!");
  }
  
  @Override
  public void onError(Context context, String errorId) {
    Log.w("C2DMReceiver-onError", errorId);
  }
  
  @Override
  protected void onMessage(Context context, Intent intent) {
    Log.i("C2DMReceiver", intent.getStringExtra("payload"));
  }
}